﻿package mortal.game.view.pack
{
    import Message.Game.*;
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.data.*;
    import mortal.mvc.core.*;

    public class PackBottomPart extends GSprite
    {
        private var _bmpYuanbao:GBitmap;
        private var _bmpTongqian:GBitmap;
        private var _bmpYuanbaoBind:GBitmap;
        private var _bmpTongqianBind:GBitmap;
        private var _goldTextBox:TextBox;
        private var _coinTextBox:TextBox;
        private var _goldBindTextBox:TextBox;
        private var _coinBindTextBox:TextBox;
        private var _btnWareHouse:GLabelButton;
        private var _btnShop:GLabelButton;
        private var _BtnDisBand:GLabelButton;
        private var _btnSell:GLabelButton;
        private var _btnZhengli:TimeButton;
        private var _CapacityTxt:BitmapNumberText;

        public function PackBottomPart()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseEnabled = true;
            this.pushUIToDisposeVec(UIFactory.bg(-1, 35, 333, 43, this, ImagesConst.PanelBg));
            var _loc_1:* = GlobalStyle.textFormatAnHuan;
            _loc_1.size = 11;
            var _loc_2:* = GlobalStyle.textFormatBai;
            _loc_2.align = AlignMode.LEFT;
            this._goldTextBox = this.createTextBox(0, 0, _loc_2);
            this._bmpYuanbao = UIFactory.bitmap(ImagesConst.Yuanbao, 140, 85, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGold) + " :", 8, 86, 40, 20, this, _loc_1));
            this._goldTextBox.toolTipData = Language.getString(35492) + Cache.instance.role.getMoneyByType(EPriceUnit._EPriceUnitGold) + "\n" + GameDefConfig.instance.getEprictUnitGetWay(EPriceUnit._EPriceUnitGold);
            this._coinTextBox = this.createTextBox(1, 0, _loc_2);
            this._bmpTongqian = UIFactory.bitmap(ImagesConst.Jinbi, 140, 112, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoin) + " :", 8, 113, 40, 20, this, _loc_1));
            this._coinTextBox.toolTipData = Language.getString(35493) + Cache.instance.role.getMoneyByType(EPriceUnit._EPriceUnitCoin) + "\n" + GameDefConfig.instance.getEprictUnitGetWay(EPriceUnit._EPriceUnitCoin);
            this._goldBindTextBox = this.createTextBox(0, 1, _loc_2);
            this._goldBindTextBox.textField.x = 61;
            this._bmpYuanbaoBind = UIFactory.bitmap(ImagesConst.Yuanbao_bind, 304, 85, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitGoldBind) + " :", 175, 86, 55, 20, this, _loc_1));
            this._goldBindTextBox.toolTipData = Language.getString(35494) + Cache.instance.role.getMoneyByType(EPriceUnit._EPriceUnitGoldBind) + "\n" + GameDefConfig.instance.getEprictUnitGetWay(EPriceUnit._EPriceUnitGoldBind);
            this._coinBindTextBox = this.createTextBox(1, 1, _loc_2);
            this._coinBindTextBox.textField.x = 61;
            this._bmpTongqianBind = UIFactory.bitmap(ImagesConst.Jinbi_bind, 305, 112, this);
            this.pushUIToDisposeVec(UIFactory.gTextField(GameDefConfig.instance.getEPrictUnitName(EPriceUnit._EPriceUnitCoinBind) + " :", 175, 113, 55, 20, this, _loc_1));
            this._coinBindTextBox.toolTipData = Language.getString(35495) + Cache.instance.role.getMoneyByType(EPriceUnit._EPriceUnitCoinBind) + "\n" + GameDefConfig.instance.getEprictUnitGetWay(EPriceUnit._EPriceUnitCoinBind);
            var _loc_3:* = new TextFormat();
            _loc_3.color = 16313037;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30062), 5, 46, 65, 20, this, _loc_3, true, false));
            _loc_3.color = 16777215;
            this._CapacityTxt = UIFactory.bitmapNumberText(42, 51, "RoleInfoNum.png", 8, 10, -1, this, 14);
            var _loc_4:int = 0;
            this._BtnDisBand = UIFactory.gLabelButton(ImagesConst.Fenjie, GLabelButton.gLoadedButton, ImagesConst.BackPackBtn_upSkin, 93, 44, 42, 24, this);
            this._BtnDisBand.toolTipData = Language.getString(35017);
            this._btnShop = UIFactory.gLabelButton(ImagesConst.SanTxt, GLabelButton.gLoadedButton, ImagesConst.BackPackBtn_upSkin, 141, 44, 42, 24, this);
            this._btnShop.toolTipData = Language.getString(35018);
            this._btnWareHouse = UIFactory.gLabelButton(ImagesConst.CanTxt, GLabelButton.gLoadedButton, ImagesConst.BackPackBtn_upSkin, 189, 44, 42, 24, this);
            this._btnSell = UIFactory.gLabelButton(ImagesConst.MaiTxt, GLabelButton.gLoadedButton, ImagesConst.BackPackBtn_upSkin, 237, 44, 42, 24, this);
            this._btnSell.toolTipData = Language.getString(35019);
            this._btnZhengli = UIFactory.timeButton("", 285, 44, 42, 24, this, "ZhengliBeibao", "PackButton", false);
            this._btnZhengli.cdTime = 10000;
            this._btnZhengli.labelBitmap = ImagesConst.ZenTxt;
            this._btnZhengli.toolTipData = Language.getString(35020);
            this.configEventListener(MouseEvent.CLICK, this.btnClickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bmpYuanbao.dispose(param1);
            this._bmpTongqian.dispose(param1);
            this._bmpYuanbaoBind.dispose(param1);
            this._bmpTongqianBind.dispose(param1);
            this._goldTextBox.dispose(param1);
            this._coinTextBox.dispose(param1);
            this._goldBindTextBox.dispose(param1);
            this._coinBindTextBox.dispose(param1);
            this._BtnDisBand.dispose(param1);
            this._CapacityTxt.dispose(param1);
            this._btnWareHouse.dispose(param1);
            this._btnSell.dispose(param1);
            this._btnShop.dispose(param1);
            this._btnWareHouse = null;
            this._btnSell = null;
            this._CapacityTxt = null;
            this._bmpYuanbao = null;
            this._bmpTongqian = null;
            this._bmpYuanbaoBind = null;
            this._bmpTongqianBind = null;
            this._goldTextBox = null;
            this._coinTextBox = null;
            this._goldBindTextBox = null;
            this._coinBindTextBox = null;
            this._btnShop = null;
            this._BtnDisBand = null;
            if (this._btnZhengli)
            {
                DisplayUtil.removeMe(this._btnZhengli);
                this._btnZhengli.dispose(param1);
                this._btnZhengli = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function createTextBox(param1:int, param2:int, param3:GTextFormat) : TextBox
        {
            var _loc_4:* = UICompomentPool.getUICompoment(TextBox);
            _loc_4.setbgStlye(ImagesConst.PanelBg, param3);
            _loc_4.textField.x = 40;
            _loc_4.textField.y = 3;
            _loc_4.textFieldHeight = 15;
            _loc_4.textFieldWidth = 80;
            _loc_4.bgHeight = 27;
            _loc_4.bgWidth = 165;
            _loc_4.x = param2 * 166;
            _loc_4.y = 83 + param1 * 26;
            _loc_4.mouseChildren = false;
            _loc_4.mouseEnabled = true;
            this.addChild(_loc_4);
            return _loc_4;
        }// end function

        private function btnClickHandler(event:MouseEvent) : void
        {
            var targetGButton:InteractiveObject;
            var arr:Array;
            var arr2:Array;
            var e:* = event;
            if (e.target.parent is GLabelButton)
            {
                targetGButton = e.target.parent;
            }
            else
            {
                targetGButton = e.target as InteractiveObject;
            }
            switch(targetGButton)
            {
                case this._btnZhengli:
                {
                    arr = Cache.instance.pack.backPackCache.getOutdatedItem();
                    if (arr.length)
                    {
                        var onCloseHandler:* = function (param1:int) : void
            {
                var _loc_2:Array = null;
                var _loc_3:SBagItem = null;
                var _loc_4:ItemData = null;
                if (param1 == Alert.YES)
                {
                    _loc_2 = [];
                    for each (_loc_4 in arr)
                    {
                        
                        if (_loc_4 && ItemsUtil.isCanSell(_loc_4))
                        {
                            _loc_3 = new SBagItem();
                            _loc_3.amount = _loc_4.serverData.itemAmount;
                            _loc_3.uid = _loc_4.serverData.uid;
                            _loc_2.push(_loc_3);
                        }
                    }
                    if (_loc_2.length > 0)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ShopSellItems, {arr:_loc_2, fun:tityItem}));
                    }
                }
                else if (param1 == Alert.NO)
                {
                    tityItem();
                }
                return;
            }// end function
            ;
                        Alert.isFlowMouse = true;
                        Alert.mode = Alert.Mode_NoneNotModal;
                        Alert.show(Language.getString(35496), null, Alert.YES | Alert.NO, null, onCloseHandler);
                    }
                    else
                    {
                        this.tityItem();
                    }
                    break;
                }
                case this._btnSell:
                {
                    if (CursorManager.currentCurSorType != CursorManager.SELL)
                    {
                        arr2 = Cache.instance.pack.backPackCache.getOutdatedItem();
                        if (arr2.length)
                        {
                            var onCloseHandler2:* = function (param1:int) : void
            {
                var _loc_2:Array = null;
                var _loc_3:SBagItem = null;
                var _loc_4:ItemData = null;
                if (param1 == Alert.YES)
                {
                    _loc_2 = [];
                    for each (_loc_4 in arr2)
                    {
                        
                        if (_loc_4 && ItemsUtil.isCanSell(_loc_4))
                        {
                            _loc_3 = new SBagItem();
                            _loc_3.amount = _loc_4.serverData.itemAmount;
                            _loc_3.uid = _loc_4.serverData.uid;
                            _loc_2.push(_loc_3);
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ShopSellItems, {arr:_loc_2}));
                }
                return;
            }// end function
            ;
                            Alert.isFlowMouse = true;
                            Alert.mode = Alert.Mode_NoneNotModal;
                            Alert.show(Language.getString(35496), null, Alert.YES | Alert.NO, null, onCloseHandler2);
                        }
                    }
                    CursorManager.currentCurSorType = CursorManager.SELL;
                    CursorManager.showCursor(CursorManager.currentCurSorType);
                    if (CursorManager.currentCurSorType == CursorManager.Arrow && GameController.warehouse.isViewShow)
                    {
                        CursorManager.currentCurSorType = CursorManager.SAVE;
                        CursorManager.showCursor(CursorManager.SAVE);
                    }
                    break;
                }
                case this._btnWareHouse:
                {
                    if (Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(84))
                    {
                        CursorManager.currentCurSorType = CursorManager.SAVE;
                        CursorManager.showCursor(CursorManager.currentCurSorType);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.WarehouseOpen));
                    }
                    else
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(35497, GameDefConfig.instance.getSystemOpenLevel(84)), MsgRollTipsType.msgRollTips3);
                    }
                    break;
                }
                case this._btnShop:
                {
                    if (!GameController.shop.isViewShow)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NPC_OpenNpcShop, 3011));
                    }
                    else
                    {
                        GameController.shop.view.hide();
                    }
                    break;
                }
                case this._BtnDisBand:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.OpenForgingPanel, ForgingConst.Page_ItemDecompose));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function tityItem() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Tity, EPlayerItemPosType._EPlayerItemPosTypeBag));
            return;
        }// end function

        public function setCoinAmount(param1:int) : void
        {
            var _loc_2:* = MoneyUtil.getFormatInt(param1);
            if (_loc_2 == this._coinTextBox.htmlText)
            {
                return;
            }
            this._coinTextBox.htmlText = MoneyUtil.getFormatInt(param1);
            return;
        }// end function

        public function setCoinBindAmount(param1:int) : void
        {
            var _loc_2:* = MoneyUtil.getFormatInt(param1);
            if (_loc_2 == this._coinBindTextBox.htmlText)
            {
                return;
            }
            this._coinBindTextBox.htmlText = MoneyUtil.getFormatInt(param1);
            return;
        }// end function

        public function setGoldAmount(param1:int) : void
        {
            var _loc_2:* = MoneyUtil.getFormatInt(param1);
            if (_loc_2 == this._goldTextBox.htmlText)
            {
                return;
            }
            this._goldTextBox.htmlText = MoneyUtil.getFormatInt(param1);
            return;
        }// end function

        public function setGoldBindAmount(param1:int) : void
        {
            var _loc_2:* = MoneyUtil.getFormatInt(param1);
            if (_loc_2 == this._goldBindTextBox.htmlText)
            {
                return;
            }
            this._goldBindTextBox.htmlText = MoneyUtil.getFormatInt(param1);
            return;
        }// end function

        public function setCapacity() : void
        {
            var _loc_1:* = Cache.instance.pack.backPackCache.itemLength;
            var _loc_2:* = Cache.instance.pack.backPackCache.capacity;
            this._CapacityTxt.text = _loc_1 + "/" + _loc_2;
            return;
        }// end function

        public function showCapacityFiler() : void
        {
            EffectManager.glowFilterReg(this._CapacityTxt, null, 1, 10, 0, 2);
            return;
        }// end function

    }
}
